package com.atguigu.gmall.cart.config;

import com.atguigu.gmall.cart.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    //    <mvc:interceptors>
//				<mvc:interceptor>
//					<mvc:mapping path="/**"/>
//					<bean class="自定义拦截器的全路径"/>
//				</mvc:interceptor>
//			</mvc:interceptors>
    @Autowired
    LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(loginInterceptor)注册拦截器，相当于<bean class="自定义拦截器的全路径"/>
        // addPathPatterns 拦截路径 <mvc:mapping path="/**"/>
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
    }
}
